//
//  EFTabBarController.m
//  EFDoctorHealth
//
//  Created by nf on 15/12/10.
//  Copyright © 2018年 NF. All rights reserved.
//

#import "EFTabBarController.h"

#import "HomeViewController.h"
#import "InsuranceViewController.h"
#import "StudyViewController.h"
#import "MallViewController.h"
#import "MyViewController.h"
#import "EFApiClient.h"

#import "EFNavigationController.h"
#import "EFTabBar.h"

@interface EFTabBarController ()<EFTabBarDelegate,UITabBarDelegate,UITabBarControllerDelegate>

@end

@implementation EFTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self post84];
   
//    [self.tabBar.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    self.tabBar.alpha = 0.95 ;
    
//    HomeViewController *homeVC = [[HomeViewController alloc]init];
//    EFNavigationController *homeNav = [[EFNavigationController alloc]initWithRootViewController:homeVC];
//
//    InsuranceViewController *insuranceVC = [[InsuranceViewController alloc]init];
//    EFNavigationController *insuranceNav = [[EFNavigationController alloc]initWithRootViewController:insuranceVC];
//
//    StudyViewController *studyVC = [[StudyViewController alloc]init];
//    EFNavigationController *studyNav = [[EFNavigationController alloc]initWithRootViewController:studyVC];
//
//    MallViewController *mallVC = [[MallViewController alloc]init];
//    EFNavigationController *mallNav = [[EFNavigationController alloc]initWithRootViewController:mallVC];
//
//    MyViewController *myVC = [[MyViewController alloc]init];
//    EFNavigationController *myNav = [[EFNavigationController alloc]initWithRootViewController:myVC];
//
//    self.viewControllers = @[homeNav,insuranceNav,studyNav,mallNav,myNav];
//    self.delegate =self ;
//
//    EFTabBar *tabbar = [[EFTabBar alloc]init];
//    tabbar.delegate = self ;
//    tabbar.backgroundColor = [UIColor whiteColor];
//    tabbar.frame = self.tabBar.bounds ;
////    tabbar.backgroundColor = kColor(46, 54, 60);
//    [self.tabBar addSubview:tabbar ];
//    _groubeTabbar = tabbar ;
//
//    NSArray *titleArray = @[@"首页",@"保险",@"学习",@"商城",@"我的"];
//    NSArray *imgArray = @[@"tabbar_home",@"tabbar_insurance",@"tabbar_study",@"tabbar_mall",@"tabbar_me"];
//
//    for (int i = 0;  i <self.viewControllers.count; i++) {
//
//        NSString *selected = [imgArray[i] stringByAppendingString:@"_select"];
//        [tabbar addTabBarButton:imgArray[i] selIcon:selected title:titleArray[i]index:i+kTabBarBtnTag];
//    }
}

- (void)tabBar:(EFTabBar *)tabBar didSelectButtonFrom:(NSUInteger)from to:(NSUInteger)to
{
    self.selectedIndex = to -kTabBarBtnTag ;
}


- (void)showViewControllerWithTag:(int)tag
{
    _groubeTabbar.selectIndex = tag +kTabBarBtnTag ;
    self.selectedIndex = tag ;
}
- (NSInteger)currentSelectIndex
{
    return _groubeTabbar.currentSelectIndex ;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)post84{
    // 1.创建请求
//    NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity:2];
////    EFAppContext *appc = [EFAppContext sharedContext];
//    [parameters setValue:@"10f0882cc050c953ad5ac9ba2f4290eb" forKey:@"token"];
//    NSString *urlStr = @"http://8.140.4.67:8080/mtsnhback/apply/info";
//    AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
//    [manager GET:urlStr parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
//
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSString *status = [NSString stringWithFormat:@"%@",responseObject[@"status"]];
//        NSLog(@"status===%@",status);
//
//        if(ISEqual(status, @"0")){
//            [self get84];
//        }else{
            [self getAll];
//        }
//
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        NSLog(@"error = %@",error);
//        [self getAll];
//    }];
}

- (void)getAll{
    
    HomeViewController *homeVC = [[HomeViewController alloc]init];
    EFNavigationController *homeNav = [[EFNavigationController alloc]initWithRootViewController:homeVC];

    InsuranceViewController *insuranceVC = [[InsuranceViewController alloc]init];
    EFNavigationController *insuranceNav = [[EFNavigationController alloc]initWithRootViewController:insuranceVC];

    StudyViewController *studyVC = [[StudyViewController alloc]init];
    EFNavigationController *studyNav = [[EFNavigationController alloc]initWithRootViewController:studyVC];

    MallViewController *mallVC = [[MallViewController alloc]init];
    EFNavigationController *mallNav = [[EFNavigationController alloc]initWithRootViewController:mallVC];

    MyViewController *myVC = [[MyViewController alloc]init];
    EFNavigationController *myNav = [[EFNavigationController alloc]initWithRootViewController:myVC];

    self.viewControllers = @[homeNav,insuranceNav,studyNav,mallNav,myNav];
    self.delegate =self ;

    EFTabBar *tabbar = [[EFTabBar alloc]init];
    tabbar.delegate = self ;
    tabbar.backgroundColor = [UIColor whiteColor];
    tabbar.frame = self.tabBar.bounds ;
//    tabbar.backgroundColor = kColor(46, 54, 60);
    [self.tabBar addSubview:tabbar ];
    _groubeTabbar = tabbar ;

    NSArray *titleArray = @[@"首页",@"保险",@"学习",@"商城",@"我的"];
    NSArray *imgArray = @[@"tabbar_home",@"tabbar_insurance",@"tabbar_study",@"tabbar_mall",@"tabbar_me"];

    for (int i = 0;  i <self.viewControllers.count; i++) {

        NSString *selected = [imgArray[i] stringByAppendingString:@"_select"];
        [tabbar addTabBarButton:imgArray[i] selIcon:selected title:titleArray[i]index:i+kTabBarBtnTag];
    }
}

- (void)get84{
    
    StudyViewController *studyVC = [[StudyViewController alloc]init];
    EFNavigationController *studyNav = [[EFNavigationController alloc]initWithRootViewController:studyVC];

    MyViewController *myVC = [[MyViewController alloc]init];
    EFNavigationController *myNav = [[EFNavigationController alloc]initWithRootViewController:myVC];

    self.viewControllers = @[studyNav,myNav];
    self.delegate =self ;

    EFTabBar *tabbar = [[EFTabBar alloc]init];
    tabbar.delegate = self ;
    tabbar.backgroundColor = [UIColor whiteColor];
    tabbar.frame = self.tabBar.bounds ;
//    tabbar.backgroundColor = kColor(46, 54, 60);
    [self.tabBar addSubview:tabbar ];
    _groubeTabbar = tabbar ;

    NSArray *titleArray = @[@"学习",@"我的"];
    NSArray *imgArray = @[@"tabbar_study",@"tabbar_me"];

    for (int i = 0;  i <self.viewControllers.count; i++) {

        NSString *selected = [imgArray[i] stringByAppendingString:@"_select"];
        [tabbar addTabBarButton:imgArray[i] selIcon:selected title:titleArray[i]index:i+kTabBarBtnTag];
    }
}

@end
























